class Demo{
    public int count = 0;
    public void add(){
        synchronized (this){
               count++;
        }
    }
    public int getCount(){
            return count;

    }
}
public class ThreadDemo {
    public static void main(String[] args) throws InterruptedException {
        Demo demo = new Demo();
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 10000; i++) {
                demo.add();
            }
        });
        t1.start();
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 10000; i++) {
                demo.add();
            }
        });
        t2.start();
        t1.join();
        t2.join();
        System.out.println(demo.getCount());
    }
}
